package cn.daniellee.plugin.otp;

import cn.daniellee.plugin.otp.command.TeleportCommand;
import cn.daniellee.plugin.otp.component.ItemGenerator;
import cn.daniellee.plugin.otp.listener.MenuListener;
import cn.daniellee.plugin.otp.listener.PlayerListener;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class OptimizedTeleport extends JavaPlugin {

    private static OptimizedTeleport instance;

    private String prefix;

    private Map<String, String> requests = new ConcurrentHashMap<>();

    @Override
    public void onEnable() {
        instance = this;

        loadConfig();

        getLogger().info(" ");
        getLogger().info(">>>>>>>>>>>>>>>>>>>>>>>> OptimizedTeleport Loaded <<<<<<<<<<<<<<<<<<<<<<<<");
        getLogger().info(">>>>> If you encounter any bugs, please contact author's QQ: 768318841 <<<<<");
        getLogger().info(" ");

        Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);
        Bukkit.getPluginManager().registerEvents(new MenuListener(), this);

        TeleportCommand command = new TeleportCommand();
        Bukkit.getPluginCommand("otpa").setExecutor(command);
        Bukkit.getPluginCommand("otpahere").setExecutor(command);
        Bukkit.getPluginCommand("otpaccept").setExecutor(command);
        Bukkit.getPluginCommand("otpdeny").setExecutor(command);
        Bukkit.getPluginCommand("otpreload").setExecutor(command);
        Bukkit.getPluginCommand("otphelp").setExecutor(command);
    }

    public void loadConfig() {
        getLogger().info("[OptimizedTeleport] Loading getConfig()...");
        if(!getDataFolder().exists()) getDataFolder().mkdirs();
        prefix = "&7[&b" + getConfig().getString("prompt-prefix", "OptimizedTeleport") + "&7] &3: &r";
        ItemGenerator.disableSkullLoad = getConfig().getBoolean("disable-skull-load", false);
        saveDefaultConfig();
    }

    @Override
    public void onDisable() {
        getLogger().info(" ");
        getLogger().info(">>>>>>>>>>>>>>>>>>>>>>>> OptimizedTeleport Unloaded <<<<<<<<<<<<<<<<<<<<<<<<");
        getLogger().info(" ");
    }



    public static OptimizedTeleport getInstance() {
        return instance;
    }

    public String getPrefix() {
        return prefix;
    }

    public Map<String, String> getRequests() {
        return requests;
    }
}
